﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using PSE.Tools.SchemaComparer.Extractor;
using System.Diagnostics;
using System.Threading;
using System.ComponentModel;
using PSE.Tools.SchemaComparer.Comparer;
using System.IO;

namespace PSE.Tools.SchemaComparer.WindowsApp
{
    /// <summary>
    /// Interaction logic for SchemaComparer.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = this;

            ucExtractor.ParentWindow = this;
            ucComparer.ParentWindow = this;
            ucCompareResultView.ParentWindow = this;

            this.Closing += new CancelEventHandler(MainWindow_Closing);
        }

        void MainWindow_Closing(object sender, CancelEventArgs e)
        {
            if (ucExtractor.Working.WaitOne(0))
            {
                if (MessageBox.Show("Atenção, a extração de Schema ainda não foi finalizada. Deseja realmente finalizar a aplicação ?", "", MessageBoxButton.YesNo) == MessageBoxResult.No)
                {
                    e.Cancel = true;
                }
                else
                {
                    ucExtractor.AbortExtract();
                }
            }
        }

        public void HideLoadingPanel()
        {
            Dispatcher.Invoke(new Action(delegate()
            {
                ucLoading.Visibility = Visibility.Collapsed;
                gridMain.IsEnabled = true;
            }));
        }

        public void ShowLoadingPanel(string text)
        {
            Dispatcher.Invoke(new Action(delegate()
                {
                    ucLoading.Visibility = Visibility.Visible;
                    ucLoading.TxtDetail = text;
                    gridMain.IsEnabled = false;
                }));
        }

        public void ShowLoadingPanel()
        {
            ShowLoadingPanel("");
        }
    }
}
